fis.require('smarty')(fis);
fis.set('namespace', 'sincerity');

fis.set('project.fileType.text', 'vue');
// fis.set('project.files', ['{src,page,layout,static,widget,components}/**']);
fis.set('project.ignore', fis.get('project.ignore').concat(['DS_store']));

// vue组件本身配置
fis.match('/src/**.vue', {
    isMod: true,
    rExt: 'js',
    useSameNameRequire: true,
    parser: [
        fis.plugin('vue-component', {
            cssScopedFlag: '_vuec', // 组件scoped占位符 
            cssScopedIdPrefix: '_v-', // hash前缀：_v-23j232jj 
            cssScopedHashType: 'sum', // hash生成模式，num：使用`hash-sum`, md5: 使用`fis.util.md5` 
            cssScopedHashLength: 8, // hash 长度，cssScopedHashType为md5时有效 
            styleNameJoin: ''
        }),
        fis.plugin('babel-6.x'),
        fis.plugin('translate-es3ify', null, 'append')
    ]
});

// 模块文件
fis.match('/{static,src}/**.js', {
    parser: [
        fis.plugin('babel-6.x'),
        fis.plugin('translate-es3ify', null, 'append')
    ],
    isMod: true
});

fis.match('static/{loader,lib,logic,guide}/**.js', {
    isMod: false
});

fis.match('static/{loader,lib}/**.js', {
    parser: null
});

//添加 vue 对 sass 的解析
fis.match('/src/{**.vue:less,**.less,**.css}', {
    rExt: 'css',
    parser: fis.plugin('less-2.x'),
    postprocessor: fis.plugin('autoprefixer'),
});

fis.hook('commonjs', {
    baseUrl: './',
    paths: {
        vue: 'node_modules/vue/dist/vue.js',
        zepto: 'node_modules/wii-zepto/dist/zepto.js',
        wmu2: 'node_modules/@tencent/wmu2/dist/wmu.common.js'
    },
    extList: ['.js', '.jsx', '.es']
});

fis.unhook('components');
fis.hook('smarty-node_modules');

// 设置成是模块化 js, 编译后会被 define 包裹。
fis.match('/node_modules/**.{js,css}', {
    isMod: true
});

fis.match('/node_modules/{wii-zepto}/**.js', {
    skipBrowserify: true
});

// var RECEIVER = 'http://dev.dc.wii.qq.com:8999/receiver';
// var PATH = '/Users/qinmudi/ericqin/deploy';

var RECEIVER = 'http://127.0.0.1:8999/receiver';
var PATH = '/Users/qinmudi/ericqin/tencentGilab/git_yn/yn_cx'; 

// var RECEIVER = 'http://10.12.91.98:8999/receiver';
// var PATH = '/data/code/website/dev.dc.wii.qq.com'; 

fis.match('/src/{components,plugins,libs}/**.{vue,js}', {
    packTo: '/pkg/components.js',
    optimizer: fis.plugin('uglify-js'),
});

fis.match('/src/{components,plugins}/**.{vue:less,less,css}', {
    packTo: '/pkg/components.css'
});

fis.match('/node_modules/**.js', {
    packTo: '/pkg/npm.js'
});

fis.match('/static/{module,lib}/**.js', {
    packTo: '/pkg/module.js'
});

const REGION = 'gz';
const APPID = '1254950508';
const BUCKET_NAME = 'spatest';
const DIR_NAME = '/fis';
const SECRETID = 'AKIDZ2KRN732HOK609N2lLkxyoS2QckwlufR';
const SECRETKEY = 'oR1RktqbAXilmj4JWktreJvLZXO3CHB4';
const cosUrl = `https://${REGION}.file.myqcloud.com/files/v2/${APPID}/${BUCKET_NAME}${DIR_NAME}`;
const localUrl = '/cx';

fis.media('remote').match('*.{png,jpg,css,less,js,vue,svg,ttf,woff}', {
    useDomain: true,
    domain: localUrl
}).match('/{static,widget}/(**)', {
    release: '/${static}/${namespace}/$0'
}).match(/\/page\/(.+?)\/(.+?)\/(.+)/i, {
    release: '/modules/$1/views/$2/$3'
}).match('/{layout,widget}/**.tpl', {
    release: '/views/${namespace}/$0'
}).match('{*-map.json,map.json}', {
    release: '/fe/config/$0'
}).match('{*.conf,deploy.json,package.json,README.md}', {
    release: false
}).match('/test/**', {
    release: false
});

fis.media('remote').match('**', {
    deploy: fis.plugin('http-push', {
        receiver: RECEIVER,
        to: PATH,
        data: {
            toweb: PATH + '/web/static',
            static: PATH + '/static'
        }
    })
});
